package com.crawler.waf.controllers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.crawler.waf.exceptions.WafHandlerExceptionResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 当安全模块出现异常抛出的时候，将转交到当前exception 控制器进行全局输出
 */
@RestController
public class SecurityExceptionController {


    @Autowired
    private WafHandlerExceptionResolver resolver;

    @RequestMapping("/exception")
    public void throwException(HttpServletRequest request, HttpServletResponse response) {

        Exception exception = (Exception) request.getAttribute("exception");
        Assert.notNull(exception);
        resolver.resolveException(request, response, this, exception);
    }
}
